import instance from "@/utils/axios.js";


// 新闻频道
function getChannels() {
    return instance ({
        url:'/v1_0/channels',
        method:'get'
    })
}

export {getChannels}


// 新闻推荐
function getArticles({channel_id,timestamp}) {
    return instance({
        url:'/v1_0/articles',
        method:'get',
        params:{
            channel_id,
            timestamp,
            with_top:1
        }
    })
}

export {getArticles}

// 文章详情
function getArticle(id) {
    return instance({
        url:"/v1_0/articles/"+id,
        method:'get',
    })
}

export {getArticle}


// 关注用户
function followingUser(id) {
    return instance({
        url:'/v1_0/user/followings',
        method:'post',
        data:{target:id}
    })
}


// 取消关注用户
function unFollowingUser(id) {
    return instance({
        url:'/v1_0/user/followings/'+id,
        method:'delete',
    })
}

export {followingUser,unFollowingUser}


// 点赞文章
function praise(id) {
    return instance({
        url:'/v1_0/article/likings',
        method:'post',
        data:{target:id}
    })
}

// 对文章取消点赞
function unPraise(id) {
    return instance({
        url:'/v1_0/article/likings/'+id,
        method:'delete',
    })
}

export {praise,unPraise}


// 不喜欢与取消不喜欢
function dislike(id) {
    return instance({
        url:'/v1_0/article/dislikes',
        method:'post',
        data:{target:id}
    })
}

// 对文章取消点赞
function unDislike(id) {
    return instance({
        url:'/v1_0/article/dislikes/'+id,
        method:'delete',
    })
}

export {dislike,unDislike}


// 搜索词联想
function getSuggestionList(q) {
    return instance({
        url:'/v1_0/suggestion',
        method:'get',
        params:{q}
    })
}

export {getSuggestionList}


// 搜索结果页面
function getSearchList(obj) {
    return instance({
        url:'/v1_0/search',
        method:'get',
        params:obj
    })
}

export {getSearchList}